Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

454
Views
Mensaje: "No coincide el token CSRF", excepción: "Symfony\Component\HttpKernel\Exception\HttpException",…}

Soy un desarrollador de PHP y actualmente me muevo hacia el marco de Laravel según mi tarea. Tengo que completar la tabla en tiempo real usando ajax, pero me quedo con un error que es un error de discrepancia del token CSRF. Por favor, ayúdenme a resolver el error. Estoy publicando solo un código corto

Guión JAVA

 <script> function getMessage() { $.ajax({ //var data = {"_token": $('#token').val()}, type:'POST', url:'/getMsg', headers: {'XSRF-TOKEN': $('meta[name="_token"]').attr('content')}, success:function(data) { $("#msg").html(data.msg); } }); } </script>

Ruta Ruta

 Route::post('/getMsg','CustomerSearchController@doAjaxTest');

Código del controlador

 public function doAjaxTest(){ $msg = "<b>Message over ajax This test is Successful</b>."; return response()->json(array('msg'=> $msg), 200); }

CÓDIGO HTML

 <center> <input type = "hidden" name = "_token" value = '<?php echo csrf_token(); ?>'> <table> <tr> <td><label>Enter Place Name</label></td> <td><input type="text" class="form-control" id="placename" name="placename" placeholder="Name Of Place"/></td> </tr> <tr> <td> <input type="submit" value="Get Message" onclick="getMessage()" /> </td> </tr> </table> <br> <!-- <div class="panel panel-default table-responsive"> <div id="dataTag"><b>All the Details according to department will be displayed</b></div> </div> --> <div id = 'msg'>This message will be replaced using Ajax. Click the button to replace the message.</div> </center>

No sé por qué me muestra una discrepancia de token CSRF cuando los encabezados contienen tokens una vez resueltos, puedo tener alguna acción en tiempo real, por favor ayuda

over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

Tuve el mismo problema. cambié APP_NAME en el archivo .env al valor predeterminado (Laravel). intentalo.

over 4 years ago · Santiago Trujillo Report

0

asegúrese de tener la etiqueta meta en el encabezado de la vista:

 <meta name="csrf-token" content="{{ csrf_token() }}" />

Luego puede inicializarlo solo una vez después de cargar la biblioteca jQuery, agregue esto:

 <script type="text/javascript"> $.ajaxSetup({ headers: { 'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content') } }); </script>

Prueba con solución

over 4 years ago · Santiago Trujillo Report

0

Si ya configuró los encabezados y aún no funciona, intente crear una nueva clave:

 php artisan key:generate
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!